<?php
class SessionSvc
{
    static $_isStart = false;
    private $driver;

    static public function getInstance($sessName)
    {
        static $ins;
        if (false == $ins instanceof self)
        {
            $ins = new self($sessName);
        }
        return $ins;
    }

    private function __construct($sessName, $driver=null)
    {
        if (null != $driver)
        {
            $driver->init();
        }
        session_name($sessName);
    }

    static private function ensureStarOnce()
    {/*{{{*/
        if (!self::$_isStart)
        {
            session_start();
            self::$_isStart = true;
        }
    }/*}}}*/

    public function setSessionID($id)
    {/*{{{*/
        session_id($id);
    }/*}}}*/

    public function getSessionID()
    {/*{{{*/
        self::ensureStarOnce(); 
        return session_id();
    }/*}}}*/

    public function save($key, $var='')
    {/*{{{*/
        self::ensureStarOnce(); 
        $_SESSION[$key] = $var;
        return true;
    }/*}}}*/

    public function get($key)
    {	/*{{{*/
        self::ensureStarOnce(); 
        if (isset($_SESSION[$key]))
            return $_SESSION[$key];
        else
            return NULL;
    }/*}}}*/

    public function destroy($key)
    {/*{{{*/
        self::ensureStarOnce(); 
        unset($_SESSION[$key]);
        return true;
    }/*}}}*/

    public function destroyAll()
    {/*{{{*/
        self::ensureStarOnce(); 
        $_SESSION = array();
        return true;
    }/*}}}*/

    public function getAll()
    {/*{{{*/
        self::ensureStarOnce(); 
        return $_SESSION;
    }/*}}}*/
}
